import { createSlice, PayloadAction } from "@reduxjs/toolkit"
import {changeLanguage} from "i18next";

export type languageType = "en" | "zh_CN"

export interface ILanguageState {
  language: languageType
}

const initialState: ILanguageState = {
  language: "en",
}

export const lanSlice = createSlice({
  name: "LANGUAGE",
  initialState,
  reducers: {
    switchLanguage: (state, action: PayloadAction<"en" | "zh_CN">) => {
      state.language = action.payload
      changeLanguage(action.payload)
    },
  },
})

// Action creators are generated for each case reducer function
export const { switchLanguage } = lanSlice.actions
export default lanSlice.reducer
